<?php
    session_start();
    require("../inc/db.class.php");
    $title= trim(mysql_escape_string($_POST['title']));
    $description = trim(mysql_escape_string($_POST['description']));
    $created_by = mysql_escape_string($_POST['created_by']);
 $created_at = mysql_escape_string($_POST['created_at']);
 $modified_at = date('Y-m-d h:i:s');
 
    $dbo= new database();
 if(isset($_POST['add'])){
  $insertAnnouncement ="insert into  ".DB_NAME.".announcements (`title`, `description`, `created_by`, `created_at`, `modified_at`) values('$title', '$description', '$created_by', '$created_at', '$modified_at') ";
	echo $insertAnnouncement; 
 if($dbo->query($insertAnnouncement))
 header("location: ../admin-announcements.php?add=1");
  else
    header("location: ../admin-announcements.php?add=0");
 } else {
  $id = $_POST['id'];
  $updateAnnouncement ="UPDATE  ".DB_NAME.".announcements SET `title`='$title', `description`='$description', `modified_at`='$modified_at' WHERE `id` =$id";
  if($dbo->query($updateAnnouncement))
    header("location: ../admin-announcements.php?update=1");
  else
    header("location: ../admin-announcements.php?update=0");

 }
        
        
?>